# Complex Numbers
2j

3 + 4j
type(3 + 4j)


#The complex constructor
complex(3)
complex(-2, 3)
complex('(-2+3j)')
complex('-2+3j')
complex('-2 + 3j')


#Operations on complex
c = 3 + 5j
c.real
c.imag
c.conjugate()


# The cmath module
import math
math.sqrt(-1)

import cmath
cmath.sqrt(-1)


#Polar coordinates
cmath.phase(1+1j)
abs(1+1j)

cmath.polar(1+1j)
modulus, phase = cmath.polar(1+1j)
modulus
phase

#The operation can be reversed
cmath.rect(modulus, phase)


#A practical example
def inductive(ohms):
    return complex(0.0, ohms)

def capacitive(ohms):
    return complex(0.0, -ohms)

def resistive(ohms):
    return complex(ohms)

def impedance(components):
    z = sum(components)
    return z

impedance([inductive(10), resistive(10), capacitive(5)])
cmath.phase(_)
math.degrees(_)